import logging

from motor.motor_asyncio import AsyncIOMotorClient


class MongoDBClient:
    db30_1: AsyncIOMotorClient = None


class DataBase:
    client: AsyncIOMotorClient = None
    htmljson = None


async def connect_to_mongo(mongodb_conn_str: str, db_name: str):
    logging.info("connecting to mongo...")
    db = DataBase()
    db.client = AsyncIOMotorClient(mongodb_conn_str,
                                   maxPoolSize=10,
                                   minPoolSize=10)
    # get a collection
    # Format db.<database_name>.<collection_name>
    setattr(DataBase, db_name, db.client[db_name])
    logging.info("connected to {}".format(db_name))
    return db


async def close_mongo_connection(db):
    logging.info("closing connection...")
    db.client.close()
    logging.info("closed connection")
